#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Created by PyCharm.
# @Project: Code_Clone_Detection_Educoder
# @File: get_single_student_result.py
# @Description: 
# @Time: 2018/12/12 21:54
# @Author: ljz

from CCDetector.utils import mysql_pool


def run(query_id, user_id):
    mysql_operator = mysql_pool.MysqlPool()
    result = mysql_operator.select_all("""
    select file_path, file_content, target_user_id, target_file_path, target_file_content, rate 
    from educoder_code_clone.result where query_id='{}' and user_id='{}'
    """.format(query_id, user_id))
    code_info = []
    for i in result:
        single_record = {'path': {'origin': i[0],
                                  'target': i[3]},
                         'content': {'origin': i[1],
                                     'target': i[4]},
                         'target_user_id': i[2],
                         'rate': i[5]}
        code_info.append(single_record)

    return code_info
